package org.jsola.hr.web;


import org.jsola.core.Result;
import org.jsola.hr.constant.HrConstants;
import org.jsola.hr.dto.SyncSocUniversalDTO;
import org.jsola.hr.dto.SyncSocWebSiteDTO;
import org.jsola.hr.service.ISyncSocWebSiteService;
import org.jsola.user.core.TokenUser;
import org.jsola.user.core.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author lyh
 */
@RestController("hrSyncSocWebSiteController")
@RequestMapping(HrConstants.API_PATH + "/v1/syncSocWebSite")
public class SyncSocWebSiteController implements ISyncSocWebSiteControllerAPI {

    @Autowired
    private ISyncSocWebSiteService syncSocWebSiteService;


    @Override
    @PostMapping(value = "/incrementSocEmp")
    public <T> Result<List<T>> incrementSocEmp(@Valid @RequestBody SyncSocWebSiteDTO syncSocWebSiteDTO) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 同步社保网站权限检验
        return Result.success(
                syncSocWebSiteService.incrementSocEmp(syncSocWebSiteDTO, tokenUser)
        );
    }

    @Override
    @PostMapping(value = "/decreaseSocEmp")
    public <T> Result<List<T>> decreaseSocEmp(@Valid @RequestBody SyncSocWebSiteDTO syncSocWebSiteDTO) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 同步社保网站权限检验
        return Result.success(
                syncSocWebSiteService.decreaseSocEmp(syncSocWebSiteDTO, tokenUser)
        );
    }

    @Override
    @PostMapping(value = "/batchSync")
    public Result<List<SyncSocUniversalDTO>> batchSync(@Valid @RequestBody SyncSocWebSiteDTO syncSocWebSiteDTO) {
        TokenUser tokenUser = UserContext.getUser();
        // todo 同步社保网站权限检验
        return Result.success(
                syncSocWebSiteService.batchSync(syncSocWebSiteDTO, tokenUser)
        );
    }

}
